﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MVVMLesson01.MVVM
{
    public class LogicClass : INotifyPropertyChanged
    {

        public event PropertyChangedEventHandler? PropertyChanged;

        public DataModel dataModel { get; set; } = new DataModel();

        private DataModel _dataModel1 = new DataModel();

        public DataModel DataModel1
        {
            get { return _dataModel1; }
            set { _dataModel1 = value; 
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DataModel1))); } //界面绑定的是Value3属性 DataModel1属性发送变化 界面是不会更新的
        }


        //public ICommand BtnCommand { get; set; } = new Command(DoLogic);//这样写是不行的 因为初始化的时候是先初始化BtnCommand 这个时候还没有DoLogic方法 所以会报错

        public ICommand BtnCommand { get; set; } //这样写才行

        public LogicClass()
        {
            BtnCommand = new Command(DoLogic);
        }

        private void DoLogic(object obj)
        {
            //dataModel.Value3 = dataModel.Value1 + dataModel.Value2;
            DataModel1.Value3 = dataModel.Value1 + dataModel.Value2;

            //_model.Value3 的变化仅仅只是模型中，跟页面没有关系
        }
    }
}
